package com.atguigu.crowd.util;

import java.lang.reflect.Type;

/**
 * 用于统一Ajax请求返回的数据类型
 * @param <T>
 */
public class ResultEntity<T> {

    public static final String SUCCESS="SUCCESS";
    public static final String FAILED="FAILED";

    //用来封装请求处理的结果
    private String result;

    //请求失败时返回的信息
    private String message;

    //要返回的数据
    private T data;


    public ResultEntity() {
    }


    public static String getSUCCESS() {
        return SUCCESS;
    }

    public static String getFAILED() {
        return FAILED;
    }

    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }


    public ResultEntity(String result, String message, T data) {
        this.result = result;
        this.message = message;
        this.data = data;
    }

    /**
     * 返回操作结果为成功，不带数据
     * @param data
     * @param <T>
     * @return
     */
    public static <T> ResultEntity<T> successWithoutData(T data){
       return new ResultEntity<T>(SUCCESS,null,data);
   }
    /**
     *
     *  返回操作结果为失败，不带数据
     *
     *  @param
     * @return
     */
    public static <T> ResultEntity<T> successWithoutData(){
        return new ResultEntity<T>(SUCCESS,null,null);
    }
    /**
     *
     *  返回操作结果为失败，不带数据
     *
     *  @param message
     * @return
     */
    public static <E> ResultEntity<E> failed(String message) {
        return new ResultEntity<E>(FAILED, message, null);
    }




    @Override
    public String toString() {
        return "ResultEntity{" +
                "result='" + result + '\'' +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
